import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class DismissDemo extends StatelessWidget {
  final List<String> items = List.generate(30, (index) => '列表可删除项${index + 1}');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('列表删除示例'),
        centerTitle: true,
      ),
      body: ListView.builder(
          //仿IOS回弹效果
          physics: BouncingScrollPhysics(),
          itemCount: items.length,
          itemBuilder: (context, index) => Dismissible(
                key: Key(items[index]),
                //item删除操作
                onDismissed: (direction) {
                  items.removeAt(index);
                  ScaffoldMessenger.of(context)
                      .showSnackBar(SnackBar(content: Text('第${index}条被删除了')));
                },
                /**
                 * dense  使文本更小，并将所有内容打包在一起
                 */
                child: ListTile(
                  dense: true,
                  isThreeLine: true,
                  leading: Icon(
                    Icons.phone,
                    color: Theme.of(context).accentColor,
                  ),
                  title: Text(items[index],),
                  subtitle: Text('左右滑动可删除item'),
                ),
              )),
    );
  }
}
